﻿using InsuranceAdjuster.ViewModels;

// Lazy Load the ViewModels so they're only instanced when necessary
namespace InsuranceAdjuster.ViewModels {
    public class ViewModelLocator {
        private readonly Services.ServiceProviderBase _serviceProvider;
        public ViewModelLocator() {
            _serviceProvider = Services.ServiceProviderBase.Instance;

            // Load the default styles
            Models.BranchStyle branchStyle = App.Current.Resources["BranchStyle"] as Models.BranchStyle;
            if (null != branchStyle) {
                branchStyle.Load();
            }

        }

        private MainPageViewModel _MainPage;
        public MainPageViewModel MainPage {
            get {
                if (_MainPage == null)
                    _MainPage = new MainPageViewModel();

                return _MainPage;
            }
        }

        private AdjusterDashboardViewModel _appointments;
        public AdjusterDashboardViewModel Appointments {
            get {
                // Lazy Load the ViewModel so it's only instanced when necessary
                // Only one ViewModel per app
                if (null == _appointments) {
                    _appointments =
                        new AdjusterDashboardViewModel(_serviceProvider.PageConductor);
                }
                return _appointments;
            }
        }

        private BranchViewModel _branch;
        public BranchViewModel Branch {
            get {
                // Lazy Load the ViewModel so it's only instanced when necessary
                // Only one ViewModel per app
                if (null == _branch) {
                    _branch = new ViewModels.BranchViewModel(_serviceProvider.PageConductor,
                                                    _serviceProvider.InsuranceAdjusterDataService);
                }
                return _branch;
            }
        }

        private VehicleViewModel _vehicle;
        public VehicleViewModel Vehicle {
            get {
                if (null == _vehicle) {
                    _vehicle = new VehicleViewModel(_serviceProvider.PageConductor,
                                                _serviceProvider.InsuranceAdjusterDataService);
                }
                return _vehicle;
            }
        }

        private ClientAnchorsViewModel _clientAnchors;
        public ClientAnchorsViewModel ClientAnchors {
            get {
                if (null == _clientAnchors) {
                    _clientAnchors = new ClientAnchorsViewModel(_serviceProvider.PageConductor);
                }
                return _clientAnchors;
            }
        }


        public ClaimViewModel Claim {
            get { return new ClaimViewModel(_serviceProvider.PageConductor); }
        }
        private SyncSettingsViewModel _syncSettings;
        public SyncSettingsViewModel SyncSettings {
            get {
                if (null == _syncSettings) {
                    _syncSettings = new SyncSettingsViewModel(_serviceProvider.PageConductor);
                }
                return _syncSettings;
            }
        }
        private SyncStatusViewModel _syncStatus;
        public SyncStatusViewModel SyncStatus {
            get {
                if (null == _syncStatus) {
                    _syncStatus = new SyncStatusViewModel(_serviceProvider.PageConductor);
                }
                return _syncStatus;
            }
        }
        private StatusBarViewModel _statusBar;
        public StatusBarViewModel StatusBar {
            get {
                if (null == _statusBar) {
                    _statusBar = new StatusBarViewModel();
                }
                return _statusBar;
            }
        }
    }
}
